package cn.tom.service.impl;

import cn.tom.entity.Teacher;
import cn.tom.mapper.TeacherMapper;
import cn.tom.service.TeacherService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.stereotype.Service;

import java.util.List;

@Service    //实例化装配到IOC容器
@CacheConfig //缓存配置
public class TeacherServiceImpl extends ServiceImpl<TeacherMapper, Teacher> implements TeacherService {
    @Autowired
    TeacherMapper teacherMapper;    //注入teacherMapper接口

    /**
     * Logger输出
     */
    private Logger log
            = LoggerFactory.getLogger(cn.tom.tool.Log.class);


    /**
     * 查询全部老师
     */
    @Override
    public List<Teacher> findAll() {
        List<Teacher> teachers = teacherMapper.selectList(null);
        return teachers;
    }


    /**
     * 根据老师ID查询
     */
    @Override
    public Teacher findById(Integer id) {
        Teacher teacher = teacherMapper.findById(id);
        return teacher;
    }


    /**
     * 添加一个老师
     */
    @Override
    public int add(Teacher teacher) {
        int insert = teacherMapper.insert(teacher);
        return insert;
    }

    /**
     * 更新一个老师
     */
    @Override
    public int update(Teacher teacher) {
        int i = teacherMapper.updateById(teacher);
        return i;
    }


    /**
     * 删除一个老师
     */
    @Override
    public int del(Integer id) {
        int i = teacherMapper.deleteById(id);
        return i;
    }
}
